package com.ruoyi.web.controller.topic;

import com.ruoyi.system.domain.Comment;
import com.ruoyi.system.domain.User;
import com.ruoyi.system.domain.vo.Result;
import com.ruoyi.system.service.ArticleService;
import com.ruoyi.system.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;


@Api(tags = "评论模块")
@RestController
@RequestMapping("/api")
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private ArticleService articleService;

    @Value("${comment.avatar}")
    private String avatar;

    @ApiOperation("新增评论")
    @PostMapping("/comments")
    public Result<?> addComment(@RequestBody Comment comment){
        return Result.success(commentService.saveComment(comment));
    }

    @ApiOperation("删除评论")
    @PostMapping("/comments/{id}/delete")
    public Result<?> deleteComment(@RequestBody Comment comment,@PathVariable("id") Long id){
        commentService.deleteComment(comment,id);
        return Result.success();
    }

    @ApiOperation("通过blogId查询评论列表")
    @GetMapping("/comments/{blogId}")
    public Result<?> commentList(@PathVariable("blogId") Long blogId){
        List<Comment> comments =
                commentService.listCommentByBlogId(blogId);
        return Result.success(comments);
    }

    @ApiOperation("通过userId查询评论列表")
    @GetMapping("/comments/userId/{userId}")
    public Result<?> commentUserIdList(@PathVariable("userId") Long userId){
        List<Comment> comments =
                commentService.getCommentByUserId(userId);
        return Result.success(comments);
    }

}
